<template>
  <div class="page-container">
    <!-- 卡片 -->
    <el-card class="card-container">
      <el-form ref="form" :model="form" label-width="80px">
        <!-- 标题 -->
        <el-form-item label="公告标题">
          <el-input
              v-model="Titel"
              placeholder="请输入公告标题"
              maxlength="15"
              show-word-limit
              style="width: 40%;"></el-input>
        </el-form-item>

          <el-form-item label="签名">
              <el-input
                      v-model="guser"
                      placeholder="请输入签名"
                      maxlength="15"
                      show-word-limit
                      style="width: 40%;"></el-input>
          </el-form-item>
        <!-- 部门 -->
        <el-form-item label="是否置顶">
          <el-select v-model="TopChoose" placeholder="请选择你的帖子带上的Tag" style="width: 30%;margin-right: 10px">
            <el-option
                v-for="(top, index) in isTop"
                :key="index"
                :label="top.text"
                :value="top.value">
            </el-option>
          </el-select>
        </el-form-item>

        <!-- 内容 -->
        <el-form-item label="内容">
          <el-input
              type="textarea"
              v-model="content"
              :rows="6"
              placeholder="请输入内容"
              maxlength="500"
              show-word-limit
              class="custom-textarea"
              style="width: 80%; max-width: 800px;"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <!-- 仅保留发布公告按钮 -->
          <button class="pushable" @click.prevent="publish">
            <span class="shadow"></span>
            <span class="edge"></span>
            <span class="front"> 发布公告 </span>
          </button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 遮罩层 -->
    <div v-if="loading" class="loading-overlay">
      <loading/>
    </div>
  </div>
</template>

<script>
import {addBulletin} from "@/api/api";
import Loading from "@/components/Loading.vue";

export default {
  name: 'TopicForm',
  components: {Loading},
  data() {
    return {
      guser:"",
      loading:false,
      Titel: '',
      isTop: [{text:'置顶',value:0}, {text:'不置顶',value: 1}],
      TopChoose: 0,
      content:'',
      form: {}
    };
  },
  created() {
  },
  methods: {
    async publish() {
      this.loading = true;
      try {
          const response = await addBulletin({
              title: this.Titel,
              top: this.TopChoose,
              content: this.content,
              guserName: this.guser
          });
          console.log(response.data);
        if (response.data.message === "成功") {
          this.$confirm('发布成功', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false,
            type: 'success'
          }).then(() => {
            this.$router.go(-1); // 返回上一页
          });
        } else {
          this.$message.error("发布失败");
        }
      } catch (error) {
        this.$message.error("发布失败");
      } finally {
        this.loading = false;
      }
    }
  },
};
</script>

<style scoped>
.page-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.card-container {
  width: 90%;
  max-width: 800px;
  padding: 20px;
}

.custom-textarea {
  width: 100%;
  max-width: 800px;
}

.el-form-item {
  width: 100%;
}

.el-select {
  width: 70%;
}

.pushable {
  position: relative;
  background: transparent;
  padding: 0px;
  border: none;
  cursor: pointer;
  outline-offset: 4px;
  outline-color: deeppink;
  transition: filter 250ms;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.shadow {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: hsl(226, 25%, 69%);
  border-radius: 8px;
  filter: blur(2px);
  will-change: transform;
  transform: translateY(2px);
  transition: transform 600ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

.edge {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  border-radius: 8px;
  background: linear-gradient(
      to right,
      hsl(248, 39%, 39%) 0%,
      hsl(248, 39%, 49%) 8%,
      hsl(248, 39%, 39%) 92%,
      hsl(248, 39%, 29%) 100%
  );
}

.front {
  display: block;
  position: relative;
  border-radius: 8px;
  background: hsl(248, 53%, 58%);
  padding: 16px 32px;
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 1rem;
  transform: translateY(-4px);
  transition: transform 600ms cubic-bezier(0.3, 0.7, 0.4, 1);
}

.pushable:hover {
  filter: brightness(110%);
}

.pushable:hover .front {
  transform: translateY(-6px);
  transition: transform 250ms cubic-bezier(0.3, 0.7, 0.4, 1.5);
}

.pushable:active .front {
  transform: translateY(-2px);
  transition: transform 34ms;
}

.pushable:hover .shadow {
  transform: translateY(4px);
  transition: transform 250ms cubic-bezier(0.3, 0.7, 0.4, 1.5);
}

.pushable:active .shadow {
  transform: translateY(1px);
  transition: transform 34ms;
}

.pushable:focus:not(:focus-visible) {
  outline: none;
}
</style>
